/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package xmarti.vacaxm.client.maintenance.animal;





import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import xmarti.vacaxm.action.ImplMaintenance;
import xmarti.vacaxm.action.ImplPerson;
import xmarti.vacaxm.beans.connect.Destination;
import xmarti.vacaxm.beans.connect.Origin;
import xmarti.vacaxm.beans.maintenance.Animal;
import xmarti.vacaxm.beans.maintenance.Breed;
import xmarti.vacaxm.beans.maintenance.Bull;
import xmarti.vacaxm.beans.maintenance.Calf;
import xmarti.vacaxm.beans.maintenance.Cow;
import xmarti.vacaxm.client.maintenance.auxiliar.JDBreed;
import xmarti.vacaxm.client.sequence.JDState;
import xmarti.vacaxm.exception.ExceptionHibernateVacaxm;
import xmarti.vacaxm.utils.TDSLanguageUtils;
import xmarti.vacaxm.utils.Utils;
import xmarti.vacaxm.utils.ValidarText;



/**
 *
 * @author xmarti
 */
public class JPAnimalData extends javax.swing.JPanel {    
    private Animal animal = null;
 
    private ImplMaintenance aMaintenance;
    private ImplPerson aPerson; 
    
    public JPAnimalData(Cow animal){
        
        initComponents();
        jLabelCaptionName.setVisible(false);
        jTextName.setVisible(false);
        initObjects();     
        this.animal=new Cow();
        this.animal=animal;   
        this.setBackground(Utils.getColorCow());
        setData();        
    }
    public JPAnimalData(Bull animal){
        
        initComponents();
        jLabelCaptionName.setVisible(true);
        jTextName.setVisible(true);
        initObjects();  
        this.animal= new Bull();
        this.animal=animal;
        this.setBackground(Utils.getColorBull());
        setData();        
    }
    public JPAnimalData(Calf animal){
        initComponents();
        jLabelCaptionName.setVisible(false);
        jTextName.setVisible(false);
        initObjects();  
        this.animal= new Calf();
        this.animal=animal;        
        this.setBackground(Utils.getColorCalf());
        setData();        
    }
    public Animal getAnimal() {
        return this.animal;
    }
    
    public void setAnimal(Animal animal) {
        this.animal = animal;
    }
    
    private void initObjects(){
        this.aMaintenance= new ImplMaintenance(); 
        this.aPerson= new ImplPerson(); 
        this.jTextSearchMother.setDocument(new ValidarText(4,true));
        this.jDateBirth.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jDateBirth.toolTipText"));
        this.jDateHigh.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jDateHigh.toolTipText"));
        this.jDateLow.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jDateLow.toolTipText"));                
        chargeBulls();
        chargeCows();
        chargeOrigins();
        chargeDestinations(); 
        chargeBreeds();
       
        
        
    }
    private void setData(){        
        if (this.animal instanceof Bull){            
            this.jTextName.setText(this.animal.getName());            
        }                
        
        this.jLabelIdentificador.setText(this.animal.getCodeAnimalToString());
        this.jDateBirth.setDate(animal.getBirthDate());
        this.jComboFather.setSelectedItem(animal.getFather());
        this.jComboMother.setSelectedItem(animal.getMother());
        this.jDateHigh.setDate(animal.getHighDate());
        this.jComboOrigin.setSelectedItem(animal.getOrigin());
        this.jDateLow.setDate(animal.getLowDate());
        this.jComboDestination.setSelectedItem(animal.getDestination());
        this.jComboBreed.setSelectedItem(animal.getBreed());
    }
    public void saveData(){        
       if (this.animal instanceof Bull)this.animal.setName(this.jTextName.getText());            
       this.animal.setBirthDate(this.jDateBirth.getDate()); 
       this.animal.setHighDate(this.jDateHigh.getDate());
       this.animal.setLowDate(this.jDateLow.getDate());
       this.animal.setFather((Bull) this.jComboFather.getSelectedItem());
       this.animal.setMother((Cow)this.jComboMother.getSelectedItem());
       this.animal.setOrigin((Origin)this.jComboOrigin.getSelectedItem());
       this.animal.setDestination((Destination)this.jComboDestination.getSelectedItem());
       this.animal.setBreed((Breed)this.jComboBreed.getSelectedItem());
    }
       
    public void chargeCows(){ 
        int id=-1; 
        if (jComboMother.getSelectedIndex() > -1) {
            Cow c =(Cow) jComboMother.getSelectedItem();
            id=c.getId();
        }        
        jComboMother.removeAllItems();
        try {                    
            jComboMother.addItem( new Cow()); 
            for(Cow c:aMaintenance.getCows())jComboMother.addItem(c);
            if(id>-1 ){
                for(int i=0;i<jComboMother.getItemCount();i++){
                    Cow c = (Cow)jComboMother.getItemAt(i);
                    if (c.getId()==id){
                        jComboMother.setSelectedIndex(i);
                        i=jComboMother.getItemCount();
                    }                      
                }          
            }
        } catch (ExceptionHibernateVacaxm ex) {
           //todo
            Logger.getLogger(JPAnimalData.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }
    public void chargeBulls(){        
        int id=-1; 
        if (jComboFather.getSelectedIndex() > -1) {
            Bull c =(Bull) jComboFather.getSelectedItem();
            id=c.getId();
        }        
        jComboFather.removeAllItems();
        try {                    
           jComboFather.addItem(new Bull(" - "));
            for(Bull c:aMaintenance.getBulls())jComboFather.addItem(c);
            if(id>-1 ){
                for(int i=0;i<jComboFather.getItemCount();i++){
                    Bull c = (Bull)jComboFather.getItemAt(i);
                    if (c.getId()==id){
                        jComboFather.setSelectedIndex(i);
                        i=jComboFather.getItemCount();
                    }                        
                }
            }
                
        } catch (ExceptionHibernateVacaxm ex) {
            //todo
            Logger.getLogger(JPAnimalData.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    public void chargeOrigins(){
        int id=-1; 
        if (jComboOrigin.getSelectedIndex() > -1) {
            Origin c =(Origin) jComboOrigin.getSelectedItem();
            id=c.getId();
        }        
        jComboOrigin.removeAllItems();        
        jComboOrigin.addItem (new Origin());
        for(Origin c:aPerson.getOrigin())jComboOrigin.addItem(c);                    
        if(id>-1){
            for(int i=0;i<jComboOrigin.getItemCount();i++){
                Origin c = (Origin)jComboOrigin.getItemAt(i);
                if (c.getId()==id){
                    jComboOrigin.setSelectedIndex(i);
                    i=jComboOrigin.getItemCount();
                }                        
            }
        }
        
        
    }   
    public void chargeDestinations(){
        int id=-1; 
        if (jComboDestination.getSelectedIndex() > -1) {
            Destination c =(Destination) jComboDestination.getSelectedItem();
            id=c.getId();
        }
        
        
        jComboDestination.removeAllItems();
        jComboDestination.addItem(new Destination());                    
        for(Destination c:aPerson.getDestinations())jComboDestination.addItem(c);                    
        if (id>-1 ){
            for(int i=0;i<jComboDestination.getItemCount();i++){
                Destination c = (Destination)jComboDestination.getItemAt(i);
                if (c.getId()==id){
                    jComboDestination.setSelectedIndex(i);
                    i=jComboDestination.getItemCount();
                }                        
            }
        }
        
    } 
    public void chargeBreeds(){
        int id=-1; 
        if (jComboBreed.getSelectedIndex() > -1) {
            Breed c =(Breed) jComboBreed.getSelectedItem();
            id=c.getId();
        }
        
        
        jComboBreed.removeAllItems();
        jComboBreed.addItem(new Breed());                    
        try {                    
            for(Breed c:aMaintenance.getBreeds())jComboBreed.addItem(c);
            if (id>-1 ){
                for(int i=0;i<jComboBreed.getItemCount();i++){
                    Breed c = (Breed)jComboBreed.getItemAt(i);
                    if (c.getId()==id){
                        jComboBreed.setSelectedIndex(i);
                        i=jComboBreed.getItemCount();
                    }                        
                }
            }
        } catch (ExceptionHibernateVacaxm ex) {
            Logger.getLogger(JPAnimalData.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    } 
    public void enabledObjects(boolean modify){            
        this.jButtonIdentificador.setEnabled(modify);
        if(this.jTextName.isVisible())this.jTextName.setEnabled(modify);
        this.jComboDestination.setEnabled(modify);
        this.jComboFather.setEnabled(modify);
        this.jComboMother.setEnabled(modify);
        this.jComboOrigin.setEnabled(modify);
        this.jDateBirth.setEnabled(modify);
        this.jDateHigh.setEnabled(modify);
        this.jDateLow.setEnabled(modify);
        this.jTextSearchMother.setEnabled(modify);
        this.jButtonSearchMother.setEnabled(modify);
        this.jComboBreed.setEnabled(modify);
    }

    public JLabel getjLabelState() {
        return jLabelState;
    }

    public void setjLabelState(JLabel jLabelState) {
        this.jLabelState = jLabelState;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelCaptionIdentificador1 = new javax.swing.JLabel();
        jButtonIdentificador = new javax.swing.JButton();
        jLabelIdentificador = new javax.swing.JLabel();
        jLabelCaptionIdentificador = new javax.swing.JLabel();
        jLabelState = new javax.swing.JLabel();
        jLabelHigh = new javax.swing.JLabel();
        jLabelOrigin = new javax.swing.JLabel();
        jComboOrigin = new javax.swing.JComboBox();
        jLabelLow = new javax.swing.JLabel();
        jLabelDestination = new javax.swing.JLabel();
        jComboDestination = new javax.swing.JComboBox();
        jLabelBirth = new javax.swing.JLabel();
        jComboFather = new javax.swing.JComboBox();
        jComboMother = new javax.swing.JComboBox();
        jLabelFather = new javax.swing.JLabel();
        jLabelMother = new javax.swing.JLabel();
        jButtonSearchMother = new javax.swing.JButton();
        jTextSearchMother = new javax.swing.JTextField();
        jLabelCaptionName = new javax.swing.JLabel();
        jTextName = new javax.swing.JTextField();
        jLabelSearchMother = new javax.swing.JLabel();
        jLabelBreed = new javax.swing.JLabel();
        jComboBreed = new javax.swing.JComboBox();
        jButtonBreed = new javax.swing.JButton();
        jDateBirth = new JCalendarXM.JTextCalendarXM();
        jDateLow = new JCalendarXM.JTextCalendarXM();
        jDateHigh = new JCalendarXM.JTextCalendarXM();

        jLabelCaptionIdentificador1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCaptionIdentificador1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelCaptionIdentificador1.setText(TDSLanguageUtils.getMessage("jPanelCowData.jLabelCaptionIdentificador.caption"));

        setBackground(new java.awt.Color(255, 204, 204));
        setAlignmentX(0.0F);
        setAlignmentY(0.0F);
        setMaximumSize(new java.awt.Dimension(36, 36));
        setMinimumSize(new java.awt.Dimension(36, 36));
        setPreferredSize(new java.awt.Dimension(0, 36));
        setLayout(null);

        jButtonIdentificador.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jButtonIdentificador.caption"));
        jButtonIdentificador.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jButtonIdentificador.toolTipText"));
        jButtonIdentificador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonIdentificadorActionPerformed(evt);
            }
        });
        add(jButtonIdentificador);
        jButtonIdentificador.setBounds(380, 60, 150, 34);

        jLabelIdentificador.setBackground(new java.awt.Color(255, 255, 204));
        jLabelIdentificador.setFont(new java.awt.Font("Tahoma", 3, 14)); // NOI18N
        jLabelIdentificador.setForeground(java.awt.Color.blue);
        jLabelIdentificador.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelIdentificador.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelIdentificador.toolTipText"));
        jLabelIdentificador.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jLabelIdentificador.setOpaque(true);
        jLabelIdentificador.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelIdentificadorMouseClicked(evt);
            }
        });
        add(jLabelIdentificador);
        jLabelIdentificador.setBounds(200, 60, 170, 30);

        jLabelCaptionIdentificador.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCaptionIdentificador.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabelCaptionIdentificador.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelCaptionIdentificador.caption"));
        jLabelCaptionIdentificador.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        add(jLabelCaptionIdentificador);
        jLabelCaptionIdentificador.setBounds(210, 36, 134, 24);

        jLabelState.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabelState.setForeground(java.awt.Color.red);
        jLabelState.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelState.setText("jLabel2");
        jLabelState.setAlignmentX(0.5F);
        jLabelState.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 5, 1, 5));
        add(jLabelState);
        jLabelState.setBounds(0, 0, 680, 30);

        jLabelHigh.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelHigh.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelHigh.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelHigh.caption"));
        add(jLabelHigh);
        jLabelHigh.setBounds(18, 160, 90, 40);

        jLabelOrigin.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelOrigin.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelOrigin.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelOrigin.caption"));
        jLabelOrigin.setMaximumSize(new java.awt.Dimension(36, 36));
        jLabelOrigin.setMinimumSize(new java.awt.Dimension(36, 36));
        jLabelOrigin.setPreferredSize(new java.awt.Dimension(0, 36));
        add(jLabelOrigin);
        jLabelOrigin.setBounds(270, 160, 110, 36);

        jComboOrigin.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jComboOrigin.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jComboOrigin.toolTipText"));
        jComboOrigin.setBorder(null);
        jComboOrigin.setMaximumSize(new java.awt.Dimension(100, 36));
        jComboOrigin.setMinimumSize(new java.awt.Dimension(70, 36));
        jComboOrigin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboOjComboChange(evt);
            }
        });
        add(jComboOrigin);
        jComboOrigin.setBounds(380, 160, 170, 36);

        jLabelLow.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelLow.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelLow.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelLow.caption"));
        add(jLabelLow);
        jLabelLow.setBounds(18, 200, 90, 37);

        jLabelDestination.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelDestination.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelDestination.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelDestination.caption"));
        jLabelDestination.setMaximumSize(new java.awt.Dimension(36, 36));
        jLabelDestination.setMinimumSize(new java.awt.Dimension(36, 36));
        jLabelDestination.setPreferredSize(new java.awt.Dimension(0, 36));
        add(jLabelDestination);
        jLabelDestination.setBounds(278, 200, 100, 36);

        jComboDestination.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jComboDestination.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jComboDestination.toolTipText"));
        jComboDestination.setBorder(null);
        jComboDestination.setMinimumSize(new java.awt.Dimension(70, 36));
        jComboDestination.setPreferredSize(new java.awt.Dimension(70, 36));
        jComboDestination.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboDestinationActionPerformed(evt);
            }
        });
        add(jComboDestination);
        jComboDestination.setBounds(380, 200, 170, 37);

        jLabelBirth.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelBirth.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelBirth.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelBirth.caption"));
        add(jLabelBirth);
        jLabelBirth.setBounds(18, 120, 92, 36);

        jComboFather.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jComboFather.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jComboFather.toolTipText"));
        jComboFather.setBorder(null);
        jComboFather.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboFatherActionPerformed(evt);
            }
        });
        add(jComboFather);
        jComboFather.setBounds(250, 120, 120, 36);

        jComboMother.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jComboMother.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jComboMother.toolTipText"));
        jComboMother.setBorder(null);
        jComboMother.setMaximumSize(new java.awt.Dimension(150, 36));
        jComboMother.setMinimumSize(new java.awt.Dimension(70, 36));
        jComboMother.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboMotherActionPerformed(evt);
            }
        });
        add(jComboMother);
        jComboMother.setBounds(380, 120, 170, 36);

        jLabelFather.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelFather.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabelFather.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelFather.caption"));
        jLabelFather.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabelFather.setMaximumSize(new java.awt.Dimension(36, 36));
        jLabelFather.setMinimumSize(new java.awt.Dimension(36, 36));
        jLabelFather.setPreferredSize(new java.awt.Dimension(0, 36));
        add(jLabelFather);
        jLabelFather.setBounds(263, 100, 100, 20);

        jLabelMother.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelMother.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabelMother.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelMother.caption"));
        jLabelMother.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabelMother.setMaximumSize(new java.awt.Dimension(36, 36));
        jLabelMother.setMinimumSize(new java.awt.Dimension(36, 36));
        jLabelMother.setPreferredSize(new java.awt.Dimension(0, 36));
        add(jLabelMother);
        jLabelMother.setBounds(390, 100, 120, 19);

        jButtonSearchMother.setIcon(new javax.swing.ImageIcon(getClass().getResource("/xmarti/vacaxm/image/BotoCercarPetit.png"))); // NOI18N
        jButtonSearchMother.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jButtonSearchMother.toolTipText"));
        jButtonSearchMother.setAlignmentY(0.0F);
        jButtonSearchMother.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSearchMotherActionPerformed(evt);
            }
        });
        add(jButtonSearchMother);
        jButtonSearchMother.setBounds(660, 120, 40, 37);

        jTextSearchMother.setBackground(new java.awt.Color(204, 255, 204));
        jTextSearchMother.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jTextSearchMother.toolTipText"));
        jTextSearchMother.setAlignmentX(0.0F);
        jTextSearchMother.setAlignmentY(0.0F);
        jTextSearchMother.setMinimumSize(new java.awt.Dimension(36, 36));
        jTextSearchMother.setPreferredSize(new java.awt.Dimension(36, 36));
        add(jTextSearchMother);
        jTextSearchMother.setBounds(560, 120, 100, 36);

        jLabelCaptionName.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCaptionName.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelCaptionName.caption"));
        jLabelCaptionName.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        add(jLabelCaptionName);
        jLabelCaptionName.setBounds(70, 36, 110, 23);

        jTextName.setBackground(new java.awt.Color(255, 255, 204));
        jTextName.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jTextName.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextName.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jTextName.toolTipText"));
        jTextName.setAlignmentX(0.0F);
        jTextName.setAlignmentY(0.0F);
        add(jTextName);
        jTextName.setBounds(60, 60, 120, 33);

        jLabelSearchMother.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelSearchMother.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelSearchMother.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelSearchMother.caption"));
        jLabelSearchMother.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabelSearchMother.setMaximumSize(new java.awt.Dimension(36, 36));
        jLabelSearchMother.setMinimumSize(new java.awt.Dimension(36, 36));
        jLabelSearchMother.setPreferredSize(new java.awt.Dimension(0, 36));
        add(jLabelSearchMother);
        jLabelSearchMother.setBounds(560, 100, 130, 19);

        jLabelBreed.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelBreed.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelBreed.setText(TDSLanguageUtils.getMessage("jPanelAnimalData.jLabelBreed.caption"));
        jLabelBreed.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabelBreed.setMaximumSize(new java.awt.Dimension(36, 36));
        jLabelBreed.setMinimumSize(new java.awt.Dimension(36, 36));
        jLabelBreed.setPreferredSize(new java.awt.Dimension(0, 36));
        add(jLabelBreed);
        jLabelBreed.setBounds(550, 40, 140, 19);

        jComboBreed.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jComboBreed.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jComboBreed.toolTipText"));
        jComboBreed.setBorder(null);
        jComboBreed.setMaximumSize(new java.awt.Dimension(150, 36));
        jComboBreed.setMinimumSize(new java.awt.Dimension(70, 36));
        jComboBreed.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBreedActionPerformed(evt);
            }
        });
        add(jComboBreed);
        jComboBreed.setBounds(550, 60, 110, 36);

        jButtonBreed.setIcon(new javax.swing.ImageIcon(getClass().getResource("/xmarti/vacaxm/image/BotoNouPetit.png"))); // NOI18N
        jButtonBreed.setToolTipText(TDSLanguageUtils.getMessage("jPanelAnimalData.jButtonBreed.toolTipText"));
        jButtonBreed.setAlignmentY(0.0F);
        jButtonBreed.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBreedActionPerformed(evt);
            }
        });
        add(jButtonBreed);
        jButtonBreed.setBounds(660, 60, 40, 36);

        jDateBirth.setFontText(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        add(jDateBirth);
        jDateBirth.setBounds(110, 120, 130, 33);

        jDateLow.setFontText(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        add(jDateLow);
        jDateLow.setBounds(110, 200, 130, 33);

        jDateHigh.setFontText(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        add(jDateHigh);
        jDateHigh.setBounds(110, 160, 130, 33);
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonIdentificadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonIdentificadorActionPerformed
       JDAnimalCode dialog = new JDAnimalCode(new javax.swing.JFrame(), true,this.animal);
       dialog.setLocationRelativeTo(null);
       dialog.setVisible(true);
       this.animal.setCountry(dialog.getAnimalCode().getCountry());
       this.animal.setControlCode(dialog.getAnimalCode().getControlCode());
       this.animal.setAreaCode(dialog.getAnimalCode().getAreaCode());
       this.animal.setAnimalCode1(dialog.getAnimalCode().getAnimalCode1());
       this.animal.setAnimalCode2(dialog.getAnimalCode().getAnimalCode2());       
       if(this.animal instanceof Bull)jLabelIdentificador.setText(this.animal.getCodeAnimalToString());
       else jLabelIdentificador.setText(this.animal.toString());
    }//GEN-LAST:event_jButtonIdentificadorActionPerformed

    private void jComboOjComboChange(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboOjComboChange
       jComboChange(evt);
    }//GEN-LAST:event_jComboOjComboChange

    private void jComboMotherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboMotherActionPerformed
        jComboChange(evt);
    }//GEN-LAST:event_jComboMotherActionPerformed

    private void jComboDestinationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboDestinationActionPerformed
        jComboChange(evt);
    }//GEN-LAST:event_jComboDestinationActionPerformed

    private void jComboFatherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboFatherActionPerformed
        jComboChange(evt);
    }//GEN-LAST:event_jComboFatherActionPerformed

    private void jButtonSearchMotherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSearchMotherActionPerformed
        int i = this.jComboMother.getSelectedIndex()+1;
        boolean arround=false;
        boolean searched=false; 
        while (!searched && i< this.jComboMother.getItemCount()){
           Cow cow= (Cow)this.jComboMother.getItemAt(i);
            if(i>0)if(cow.getAnimalCode2().contains(this.jTextSearchMother.getText())) searched=true; 
            if(!searched)i++;
            if(i==this.jComboMother.getItemCount() &&!arround){i=0; arround=true;}
        }
        if(searched) this.jComboMother.setSelectedIndex(i);        
    }//GEN-LAST:event_jButtonSearchMotherActionPerformed

    private void jLabelIdentificadorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelIdentificadorMouseClicked
       if(jButtonIdentificador.isEnabled()) jButtonIdentificadorActionPerformed(null); 
    }//GEN-LAST:event_jLabelIdentificadorMouseClicked

    private void jComboBreedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBreedActionPerformed
        jComboChange(evt);
    }//GEN-LAST:event_jComboBreedActionPerformed

    private void jButtonBreedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBreedActionPerformed
       final JDBreed dialog = new JDBreed();               
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
        chargeBreeds();
            
    }//GEN-LAST:event_jButtonBreedActionPerformed
    
   private void jComboChange(java.awt.event.ActionEvent evt) {                                             
        JComboBox jCombo = (JComboBox) evt.getSource();
        if (jCombo.getSelectedIndex()==0) jCombo.setSelectedIndex(-1);
    }    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonBreed;
    private javax.swing.JButton jButtonIdentificador;
    private javax.swing.JButton jButtonSearchMother;
    private javax.swing.JComboBox jComboBreed;
    private javax.swing.JComboBox jComboDestination;
    private javax.swing.JComboBox jComboFather;
    private javax.swing.JComboBox jComboMother;
    private javax.swing.JComboBox jComboOrigin;
    private JCalendarXM.JTextCalendarXM jDateBirth;
    private JCalendarXM.JTextCalendarXM jDateHigh;
    private JCalendarXM.JTextCalendarXM jDateLow;
    private javax.swing.JLabel jLabelBirth;
    private javax.swing.JLabel jLabelBreed;
    private javax.swing.JLabel jLabelCaptionIdentificador;
    private javax.swing.JLabel jLabelCaptionIdentificador1;
    private javax.swing.JLabel jLabelCaptionName;
    private javax.swing.JLabel jLabelDestination;
    private javax.swing.JLabel jLabelFather;
    private javax.swing.JLabel jLabelHigh;
    private javax.swing.JLabel jLabelIdentificador;
    private javax.swing.JLabel jLabelLow;
    private javax.swing.JLabel jLabelMother;
    private javax.swing.JLabel jLabelOrigin;
    private javax.swing.JLabel jLabelSearchMother;
    private javax.swing.JLabel jLabelState;
    private javax.swing.JTextField jTextName;
    private javax.swing.JTextField jTextSearchMother;
    // End of variables declaration//GEN-END:variables
}
